package com.okilo.online.app.act

import android.view.View
import com.okilo.online.app.R
import com.okilo.online.app.common.OkiloComAct
import com.okilo.online.app.databinding.OkiloActAdviceTypePageBinding
import com.okilo.online.app.event.OkiloEventPointType
import com.okilo.online.app.tools.OkiloTitleBarUtil
import com.okilo.online.app.tools.apt.OkiloOnSingleClickListener
import com.okilo.online.app.tools.helper.OkiloConfigCustomerHp
import com.okilo.online.app.act.OkiloFeedbackAct
import com.okilo.online.app.act.OkiloOnlineChatAct

/**
 * 建议类型
 */
class OkiloAdviceTypeAct: OkiloComAct() {
    lateinit var binding: OkiloActAdviceTypePageBinding
    //默认选择Feedback
    private var selectType = "FEEDBACK"

    override val pageName: String = "User_Advice_Type_Page"

    override fun createOkiloContentView(): View {
        binding = OkiloActAdviceTypePageBinding.inflate(layoutInflater)
        return binding.root
    }

    override fun initializeOkiloViews() {
        getTitleBarManager()
            .setTitleBarVisibility(View.VISIBLE)
            .setTitle(getString(R.string.okilo_service_customer_feedback))
            .setTitleColor(getColor(R.color.okilo_color_black))
            .setRightButtonIcon(R.mipmap.okilo_root_customer_icon)
            .setBackButtonIcon(R.mipmap.okilo_root_back_icon)
            .setTitleBarColor(getColor(R.color.okilo_color_white))
            .setRootBackgroundColor(getColor(R.color.okilo_color_ffeff1f3))
        OkiloTitleBarUtil.setStatusBarLightMode(this, true)
    }

    override fun setupOkiloEventListeners() {
        super.setupOkiloEventListeners()
        //意见反馈
        binding.okiloAdviceFeedbackLayout.setOnClickListener(object : OkiloOnSingleClickListener(){
            override fun onSingleClick(v: View?) {
                addEventPointRequestAction(OkiloEventPointType.OKILO_CLICK_TRACK.ADVICE_TYPE_FEEDBACK)
                selectType = "FEEDBACK"
                checkOkiloAdviceTypeSelected()
            }
        })
        //在线客服
        binding.okiloAdviceOnlineLayout.setOnClickListener(object : OkiloOnSingleClickListener(){
            override fun onSingleClick(v: View?) {
                addEventPointRequestAction(OkiloEventPointType.OKILO_CLICK_TRACK.ADVICE_TYPE_ONLINE)
                selectType = "ONLINE"
                checkOkiloAdviceTypeSelected()
            }
        })
        //提交
        binding.okiloAdviceButtonSubmit.setOnClickListener(object : OkiloOnSingleClickListener(){
            override fun onSingleClick(v: View?) {
                addEventPointRequestAction(OkiloEventPointType.OKILO_CLICK_TRACK.ADVICE_TYPE_SUBMIT,selectType)
                sOkiloAdviceTypeSubmit()
            }
        })

    }

    override fun loadOkiloData() {
        //是否显示在线客服入口
        val isShowCustomerChat = OkiloConfigCustomerHp.iOkiloCustomerChat()
        if (isShowCustomerChat){
            binding.okiloAdviceOnlineLayout.visibility = View.VISIBLE
        } else {
            binding.okiloAdviceOnlineLayout.visibility = View.GONE
        }
        selectType = "FEEDBACK"
        checkOkiloAdviceTypeSelected()
    }

    /**
     * 切换选择意见类型
     */
    private fun checkOkiloAdviceTypeSelected(){
        binding.okiloAdviceFeedbackLayout.setBackgroundResource(R.drawable.okilo_white_radius12)
        binding.okiloAdviceFeedbackSelect.setImageResource(R.mipmap.okilo_ulog_pp_check_normal)

        binding.okiloAdviceOnlineLayout.setBackgroundResource(R.drawable.okilo_white_radius12)
        binding.okiloAdviceOnlineSelect.setImageResource(R.mipmap.okilo_ulog_pp_check_normal)
        when(selectType){
            "FEEDBACK" -> {
                binding.okiloAdviceFeedbackLayout.setBackgroundResource(R.drawable.okilo_advice_type_select_bg)
                binding.okiloAdviceFeedbackSelect.setImageResource(R.mipmap.okilo_ulog_pp_check_selected)
            }
            else -> {
                binding.okiloAdviceOnlineLayout.setBackgroundResource(R.drawable.okilo_advice_type_select_bg)
                binding.okiloAdviceOnlineSelect.setImageResource(R.mipmap.okilo_ulog_pp_check_selected)
            }
        }
    }

    /**
     * 提交
     */
    private fun sOkiloAdviceTypeSubmit(){
        when(selectType){
            "FEEDBACK" -> {
                onIntent(OkiloFeedbackAct::class.java)
            }
            else -> {
                onIntent(OkiloOnlineChatAct::class.java)
            }
        }
    }
}